package com.polaris.live.constant

import androidx.annotation.IntDef
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.constant.UserConst.UserRole.ROlE_MANAGER
import com.polaris.live.utils.BitwiseUtils

/**
 * AppConst
 *
 * @author Created by lucas on 2023/11/23 20:19
 */
object UserConst {

    /**
     * 来源类型
     */
    object From {

        const val UNKNOWN = 0               //未知
        const val SINGLE = 1                //私聊页
        const val HOT = 2                   //热门页
        const val RECOMMEND = 3             //推荐页
        const val NEWCOMERS = 4             //新人页
        const val LIVE = 5                  //直播页
        const val MATCH = 6                 //匹配页
        const val COMMUNITY = 7             //社区页
        const val MY = 11                   //我的页
        const val NOTICE = 13               //新人邀约
        const val CALL_END = 701            //通话结束
        const val USER_CARD = 505           //资料卡片卡片
    }

    @IntDef(
        From.UNKNOWN,
        From.SINGLE,
        From.HOT,
        From.RECOMMEND,
        From.NEWCOMERS,
        From.LIVE,
        From.MATCH,
        From.MY,
        From.NOTICE,
        From.CALL_END
    )
    annotation class FromType

    /**
     * 当前页类型
     */
    object LastFrom {

        const val UNKNOWN = 0           //未知
        const val SINGLE = 1            //私聊页
        const val HOT = 2               //热门页
        const val RECOMMEND = 3         //推荐页
        const val NEWCOMERS = 4         //新人页
        const val LIVE = 5              //直播页
        const val MATCH = 6             //匹配页
        const val OTHER_SPACE = 12      //他人空间
        const val NOTICE = 13           //新人邀约
        const val SYSTEM_MESSAGE = 101  //系统消息
        const val LIVE_DETAIL = 501     //直播详情
        const val CALL_END = 701        //通话结束
    }

    @IntDef(
        LastFrom.UNKNOWN,
        LastFrom.SINGLE,
        LastFrom.HOT,
        LastFrom.RECOMMEND,
        LastFrom.NEWCOMERS,
        LastFrom.LIVE,
        LastFrom.MATCH,
        LastFrom.OTHER_SPACE,
        LastFrom.NOTICE,
        LastFrom.SYSTEM_MESSAGE,
        LastFrom.LIVE_DETAIL,
        LastFrom.CALL_END
    )
    annotation class LastFromType

    /**
     * 用户设置类型
     */
    object UserSetting {

        const val LIVE_NOTICE = 2        //直播通知开关
        const val CHAT_NOTICE = 3        //消息通知开关
        const val CALL_NOTICE = 4        //音视频通知开关
        const val MESSAGE_DND = 5        //消息勿扰开关
        const val LUCKY_BAG_NOTICE = 6   //福袋通知开关
        const val LIVE_MODULE_SWITFCH = 7//直播功能开关
        const val MINIMIZE = 8          //最小化
        const val INVITE_DO_NOT_DISTURB = 9         //房间邀请消息免打扰
    }

    @IntDef(
        UserSetting.LIVE_NOTICE,
        UserSetting.CHAT_NOTICE,
        UserSetting.CALL_NOTICE,
        UserSetting.MESSAGE_DND,
        UserSetting.LUCKY_BAG_NOTICE,
        UserSetting.LIVE_MODULE_SWITFCH,
        UserSetting.MINIMIZE,
        UserSetting.INVITE_DO_NOT_DISTURB
    )
    annotation class SettingType

    /**
     * 用户广告来源
     */
    object FlagFrom {

        const val FB_COME = 2               //facebook
    }

    @IntDef(
        FlagFrom.FB_COME
    )
    annotation class FlagFromType

    object GameStatus {

        const val WAITING = 0           //等待中
        const val READY = 1             //已准备好
        const val PLAYING = 2           //进行中
        const val FINISHED = 3          //已结束
    }

    @IntDef(
        GameStatus.WAITING,
        GameStatus.READY,
        GameStatus.PLAYING,
        GameStatus.FINISHED
    )
    annotation class RoomGameStatus

    /**
     * 查询榜单
     */
    object ContributionStatus {

        const val DAY1 = 1           //今日
        const val DAY7 = 7           //7日
        const val DAY30 = 30           //30日
    }

    @IntDef(
        ContributionStatus.DAY1,
        ContributionStatus.DAY7,
        ContributionStatus.DAY30,
    )
    annotation class ContributionType


    //=====角色
    object UserRole {

        const val ROlE_COUNTRY_BD: Long = 1L                    // 国家经理，最顶级的经理角色，下面管理地区经理 1

        const val ROlE_PROVINCE_BD: Long = 1L shl 1             //地区经理，由国家经理管理，下面管理公会长 2

        const val ROlE_CUSTOMER_SERVICE: Long = 1L shl 2        // 主要用于显示一个客服标识 4

        const val ROlE_INVITED_WHALE: Long = 1L shl 3           //特指被邀请壕用户，[鲸鱼玩家] 8

        const val ROlE_TRADER: Long = 1L shl 4                  //币商 16

        const val ROlE_MANAGER: Long = 1L shl 5                 //用户级管理员 32
    }


    /**
     * 是不是用户级管理员可以管理用户禁言和封禁
     */
    fun isManage(): Boolean {
        return UserManager.getUser().flag?.role?.let {
            BitwiseUtils.isBitwise(it, ROlE_MANAGER)
        } ?: false
    }

    /**
     * 是不是 国家经理、BD、客服
     */
    fun userFamilyOrBD(): Boolean {
        val role = UserManager.getUser().flag?.role ?: return false

        return BitwiseUtils.isBitwise(role, UserRole.ROlE_COUNTRY_BD) ||
                BitwiseUtils.isBitwise(role, UserRole.ROlE_PROVINCE_BD) ||
                BitwiseUtils.isBitwise(role, UserRole.ROlE_CUSTOMER_SERVICE)
    }
}